/**************************************************************************
SOCIAL TIES IN ACADEMIA: SOCIAL TIES IN ACADEMIA
by Tommaso Colussi
do file: Table 2
**************************************************************************/
cd ${Dir}
do MASTER.do
set more off

/***********************************************************************
Table 2 column (1): Authors' Characteristics at the time of publication
************************************************************************/
use "${DirALL}ARTICLES.dta", clear
bys articletitle author: keep if _n==1
merge m:1 author year  using "${DirALL}AUTHORS.dta"
drop if _m==2 /*_m=1 unknwon, _m=2 missing years*/

*N of authors
tabstat author, stats(max)

*Gender
gen male=(gender_a=="M")
replace male=. if _m==1
tab male

*Full Professors
gen professor=(facultyposition_a=="PROFESSOR")
replace professor=. if _m==1
tab professor

*Early career
cap drop early_c
gen early_carrer=(year-phdyear_a<=6 & phdyear_a!=. & year-phdyear_a>=0)
tab  early_c

*Institution of appointment 
preserve
g dd=(_m==3)
egen nonmissing=sum(dd)
collapse (count) author (max) nonmissing, by(faculty_a)
gsort -author
replace author=author/nonmissing
drop if faculty==""
list faculty_a author in 1/6
restore

*PhD university 
preserve
g dd=(_m==3)
egen nonmissing=sum(dd)
collapse (count) author (max) nonmissing, by(phd_a)
gsort -author
replace author=author/nonmissing
drop if phd_a==""
list phd_a author in 1/6
restore

*connections
use "${DirALL}CONNECTIONS.dta",clear
collapse (max) conn_*, by(author year)
keep conn_phd conn_ever conn_advisor conn_author  author year
gen conn_pooled=0
foreach gg of varlist conn_phd conn_ever conn_advisor conn_author {
replace conn_pooled=1 if `gg'==1
}
merge 1:m author year using "${DirALL}ARTICLES.dta"
keep if _m==3
cap drop xx
gsort author year 
bys author: keep if _n==1
*tab connections
foreach gg of varlist conn_phd conn_ever conn_advisor conn_author conn_poo{
tab `gg' 
}

/***********************************************************************
Table 2 column (2): Editors' characteristics
************************************************************************/
use "${DirALL}ARTICLES.dta", clear
keep if incharge==1
bys name year: keep if _n==1
merge 1:1 name year using "${DirALL}EDITORS.dta"
keep if _m==3

*N of editors
egen gg=group(name)
sum gg

*Gender
gen male=(gender=="M")
replace male=. if _m==1
tab male

*Full Professor
gen professor=(facultyposition=="PROFESSOR")
tab professor

*Early Career
cap drop early_c
gen early_carrer=(year-phdyear<6 & phdyear!=. & year-phdyear>=0)
tab  early_c

*Institution of appointment and phd
tab faculty
tab phd


